import { Form, Input, Button, Card, message } from "antd";
import { UserOutlined, LockOutlined } from "@ant-design/icons";
import { useHistory } from "react-router-dom";
import AdminsApi from "../../api/admins";
// eslint-disable-next-line
export default () => {
  let history = useHistory();
  //事件绑定
  const onFinish = async (values) => {
    const { status } = await AdminsApi.reg(values);
    if (status) {
      message.success({
        content: "注册成功，即将跳转登录",
        duration: 2,
        onClose: () => {
          history.push(`/login/${values.username}`);
        },
      });
    } else {
      message.error({
        content: "注册失败，请重新注册",
        duration: 2,
      });
    }
  };
  return (
    <div className="site-card-border-less-wrapper backImg" style={{ height: "100vh" }}>
      <h1 style={{ color: "#EFF5FB", position: "absolute", top: "45px", left: "630px" }}>舞东风后台管理员注册</h1>
      <Card
        title="用户注册"
        bordered={false}
        style={{ width: 300, margin: "auto", marginTop: "20vh" }}
      >
        <Form
          name="normal_login"
          className="login-form"
          initialValues={{
            remember: true,
          }}
          onFinish={onFinish}
        >
          <Form.Item
            name="username"
            rules={[
              {
                required: true,
                message: "请输入用户名!",
              },
            ]}
          >
            <Input
              prefix={<UserOutlined className="site-form-item-icon" />}
              placeholder="Username"
            />
          </Form.Item>
          <Form.Item
            name="password"
            rules={[
              {
                required: true,
                message: "请输入密码!",
              },
            ]}
          >
            <Input
              prefix={<LockOutlined className="site-form-item-icon" />}
              type="password"
              placeholder="Password"
            />
          </Form.Item>

          <Form.Item>
            <Button
              type="primary"
              htmlType="submit"
              className="login-form-button"
            >
              注册
            </Button>
          </Form.Item>
        </Form>
      </Card>
    </div>
  );
};
